import OrderModel from "../../../../../models/Order";

const orderModel = new OrderModel()

Component({
  properties: {
    item: {
      type: Object,
      value: {}
    }
  },
  data: {},
  methods: {
    resetPay() {
      orderModel.orderResetPay({ order_id: this.properties.item.id }).then(() => {
        const serial = {
          order_id: this.properties.item.id
        }
        wx.navigateTo({
          url: '/sub_main/pages/pay/index?serial=' + JSON.stringify(serial)
        })
      })
    },
    remove() {
      wx.showModal({
        title: '确认要删除吗?',
        success: res => {
          if (res.confirm) {
            orderModel.orderDelete({ order_id: this.properties.item.id }).then(() => {
              wx.showToast({
                title: '删除成功',
                success: () => {
                  setTimeout(() => {
                    wx.redirectTo({
                      url: '/sub_service/pages/order/index?type=2'
                    }, 1000)
                  })
                }
              })
            })
          }
        }
      })
    },
    viewExpress() {

    },
    confirmReceived() {
      orderModel.orderConfirmReceived({ order_id: this.properties.item.id }).then(() => {
        wx.showToast({
          title: '删除成功',
          success: () => {
            setTimeout(() => {
              wx.redirectTo({
                url: '/sub_service/pages/order/index?type=4'
              }, 1000)
            })
          }
        })
      })
    },
    comment() {
      wx.showToast({
        title: '评价已经关闭',
        icon: 'error'
      })
    },
    service() {
      wx.showToast({
        title: '请联系客服',
        success: () => {
          setTimeout(() => {
            wx.navigateTo({
              url: '/sub_common/pages/service/index'
            })
          }, 600)
        }
      })
    },
    finish() {
      orderModel.orderFinish({ order_id: this.properties.item.id }).then(() => {
        wx.showToast({
          title: '操作成功',
          success: () => {
            setTimeout(() => {
              wx.redirectTo({
                url: '/sub_service/pages/order/index?type=6'
              }, 1000)
            })
          }
        })
      })
    }
  }
});
